//
//  ZYEasyMacro.h
//  ZYEasyMacroDemo
//
//  Created by dongshangxian on 15/10/8.
//  Copyright © 2015年 Sankuai. All rights reserved.
//

#ifndef ZYEasyMacro_h
#define ZYEasyMacro_h

#define Prefix ZY

/** 字体*/
#define ZYFont(x) [UIFont systemFontOfSize:x]
#define ZYBoldFont(x) [UIFont boldSystemFontOfSize:x]

/** 颜色*/
#define ZYRGBColor(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define ZYRGBAColor(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define ZYRGB16Color(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
/**导航栏标题颜色*/
#define ZY_NAV_TITLE_COLOR [UIColor colorWithRed:17/255.0 green:131/255.0 blue:217/255.0 alpha:1]
/**表格视图背景颜色*/
#define ZY_TABLEVIEW_BACK_COLOR [UIColor colorWithRed:247/255.0 green:248/255.0 blue:249/255.0 alpha:1]
/**线的颜色*/
//#define ZY_LINE_COLOR [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1]
#define ZY_LINE_COLOR [[UIColor lightGrayColor] colorWithAlphaComponent:0.5]
/**登录注册按钮颜色*/
#define ZY_LOGIN_RIGISTER_BTN_COLOR [UIColor colorWithRed:147/255.0 green:180/255.0 blue:96/255.0 alpha:1]
/** 输出*/
#ifdef DEBUG
#define ZYLog(...) NSLog(__VA_ARGS__)
#else
#define ZYLog(...)
#endif

#define LOGIN_FAILURE @"Login Failure"

/** 获取硬件信息*/
#define ZYSCREEN_W [UIScreen mainScreen].bounds.size.width
#define ZYSCREEN_H [UIScreen mainScreen].bounds.size.height
#define ZYCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#define ZYCurrentSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]


/** 适配*/
#define ZYiOS_5_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)
#define ZYiOS_6_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define ZYiOS_7_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define ZYiOS_8_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define ZYiOS_9_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
#define ZYiOS_11_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0)

#define ZYiPhone4_OR_4s    (ZYSCREEN_H == 480)
#define ZYiPhone5_OR_5c_OR_5s   (ZYSCREEN_H == 568)
#define ZYiPhone6_OR_6s   (ZYSCREEN_H == 667)
#define ZYiPhone6Plus_OR_6sPlus   (ZYSCREEN_H == 736)
#define ZYiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

/** 弱指针*/
#define ZYWeakSelf(weakSelf) __weak __typeof(&*self)weakSelf = self;

/** 加载本地文件*/
#define ZYLoadImage(file,type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]
#define ZYLoadArray(file,type) [UIImage arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]
#define ZYLoadDict(file,type) [UIImage dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]

/** 多线程GCD*/
#define ZYGlobalGCD(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define ZYMainGCD(block) dispatch_async(dispatch_get_main_queue(),block)

/** 数据存储*/
#define ZYUserDefaults [NSUserDefaults standardUserDefaults]
#define ZYCacheDir [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
#define ZYDocumentDir [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
#define ZYTempDir NSTemporaryDirectory()

#define DEFINE_SINGLETON_INTERFACE(className) \
+ (className *)shared##className;


#define DEFINE_SINGLETON_IMPLEMENTATION(className) \
static className *shared##className = nil; \
static dispatch_once_t pred; \
\
+ (className *)shared##className { \
dispatch_once(&pred, ^{ \
shared##className = [[super allocWithZone:NULL] init]; \
if ([shared##className respondsToSelector:@selector(setUp)]) {\
[shared##className setUp];\
}\
}); \
return shared##className; \
} \
\
+ (id)allocWithZone:(NSZone *)zone { \
return [self shared##className];\
} \
\
- (id)copyWithZone:(NSZone *)zone { \
return self; \
}
//-------------------单例化一个类-------------------------
#define INITWITHSETUP \
\
- (instancetype)init {\
self = [super init];\
if (self) {\
[self setUp];\
}\
return self;\
}\
//-------------------带颜色的log-------------------------
#define XCODE_COLORS_ESCAPE_MAC @"\033["
#define XCODE_COLORS_ESCAPE_IOS @"\xC2\xA0["

#if 0
#define XCODE_COLORS_ESCAPE  XCODE_COLORS_ESCAPE_IOS
#else
#define XCODE_COLORS_ESCAPE  XCODE_COLORS_ESCAPE_MAC
#endif

#define XCODE_COLORS_RESET_FG  XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color
#define XCODE_COLORS_RESET_BG  XCODE_COLORS_ESCAPE @"bg;" // Clear any background color
#define XCODE_COLORS_RESET     XCODE_COLORS_ESCAPE @";"   // Clear any foreground or background color

#define LogBlue(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg0,0,255;" frmt XCODE_COLORS_RESET), ##__VA_ARGS__)

#ifdef __OPTIMIZE__
# define LogBlue(__FORMAT__, ...) {}
#else
# define LogBlue(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg0,0,255;" frmt XCODE_COLORS_RESET), ##__VA_ARGS__)
#endif
//-------------------带颜色的log-------------------------


#define NULLString(string) ((![string isKindOfClass:[NSString class]])||[string isEqualToString:@""] || (string == nil) || [string isEqualToString:@""] || [string isKindOfClass:[NSNull class]]||[[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)
//----空字符串判断


#define GetRectNavAndStatusHight  self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height
//----导航栏和状态栏高度

#define isPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
//----判断是否iphonex

#define SafeAreaTopHeight (isPhoneX ? 88 : 64)
//----iphonex 导航栏高度

#define SafeAreaBottomHeight (isPhoneX ? 34 : 0)
//----底部高度

#endif /* ZYEasyMacro_h */
